home *** CD-ROM | disk | FTP | other *** search
- program UpdateDCI;
-
- uses
- SysUtils,
- Registry,
- Windows,
- Classes,
- ShellAPI,
- Dialogs,
- Controls;
-
- const
- DelphiRegPath = 'Software\Borland\Delphi';
- Delphi3 = '3.0';
- Delphi4 = '4.0';
- Delphi5 = '5.0';
- CodeTemplateFileName = '\Bin\Delphi32.dci';
- DelphiExe = '\Bin\Delphi32.exe';
-
- //Update these constants as appropriate
-
- //Your Code Template as stored in the DCI file (Name | Description)
- Template = 'day | Comment for today';
- //Your version of Delphi
- MyDelphi = Delphi5;
- //Your desired comment string, with a placeholder for the date
- Comment = '%s - BL';
- //Your preferred date format
- DateFormat = 'd/mm/yyy';
- //Where Delphi should start, relative to its root.
- //Make sure you prefix with a \
- DelphiStartDir = '\Projects';
- //Custom command-line parameters for Delphi
- DelphiStartParams = '/np /hm /hv';
-
- var
- DelphiRoot: String;
- CodeTemplates: String;
- TemplateStart, TemplateEnd: Integer;
- Reg: TRegIniFile;
- TemplateFile: TStream;
-
- procedure RunDelphi;
- begin
- ShellExecute(0, nil, PChar(DelphiRoot + DelphiExe),
- DelphiStartParams, PChar(DelphiRoot + DelphiStartDir), SW_SHOWNORMAL)
- end;
-
- begin
- try //Application exception handler
- Reg := TRegIniFile.Create('');
- try
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- if not Reg.OpenKey(DelphiRegPath, False) then
- raise Exception.Create('Delphi information not found.');
- DelphiRoot := Reg.ReadString(MyDelphi, 'RootDir', '');
- if DelphiRoot = '' then
- raise Exception.Create('Delphi root path not found.')
- finally
- Reg.Free
- end;
- //Read DCI file into a string
- TemplateFile := TFileStream.Create(
- DelphiRoot + CodeTemplateFileName,
- fmOpenRead or fmShareDenyWrite);
- try
- SetLength(CodeTemplates, TemplateFile.Size);
- TemplateFile.Read(CodeTemplates[1], TemplateFile.Size)
- finally
- TemplateFile.Free
- end;
- //Locate our template
- TemplateStart := Pos(Template, CodeTemplates);
- if TemplateStart = 0 then
- raise Exception.Create('Custom Code Template not found.');
- //Now locate the comment
- while CodeTemplates[TemplateStart] <> '{' do
- Inc(TemplateStart);
- TemplateEnd := TemplateStart;
- while CodeTemplates[TemplateEnd] <> '}' do
- Inc(TemplateEnd);
- //Substitute old date for today's date
- Delete(CodeTemplates, TemplateStart, TemplateEnd - TemplateStart + 1);
- Insert(Format('{ ' + Comment + ' }', [FormatDateTime(DateFormat, Date)]),
- CodeTemplates, TemplateStart);
- //Write DCI string back to file
- TemplateFile := TFileStream.Create(
- DelphiRoot + '\' + CodeTemplateFileName,
- fmCreate);
- try
- TemplateFile.Write(CodeTemplates[1], Length(CodeTemplates));
- finally
- TemplateFile.Free
- end
- except
- //If there is a problem, check it's ok to launch Delphi, otherwise leave
- on E: Exception do
- if MessageDlg(
- Format('%s'#13#13'Continue loading Delphi', [E.Message]),
- mtError, [mbOk, mbCancel], 0) = mrCancel then
- Exit
- end;
- //Launch Delphi now template has been updated
- RunDelphi
- end.
-